package com.zhang.cloudalibabasentinelservice8401.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zhang.cloudalibabasentinelservice8401.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class FlowLimitController {
	@Autowired
	TestService testService;

	@GetMapping("/testA")
	public String testA() throws InterruptedException {
		TimeUnit.SECONDS.sleep(5);
		return testService.common();
	}

	@GetMapping("/testB")
	public String testB() {
		return testService.common();
	}

	@GetMapping("/testHotKey")
	@SentinelResource(value = "testHotKey", blockHandler = "handler_HotKey")
	public String testHotKey(
			@RequestParam(value = "hot1", required = false) String hot1,
			@RequestParam(value = "hot2", required = false) String hot2,
			@RequestParam(value = "hot3", required = false) String hot3) {
		return "----testHotKey";
	}
	public String handler_HotKey(String hot1, String hot2, String hot3, BlockException ex) {
		return "系统繁忙，请稍后重试！";
	}
}